import java.math.BigDecimal;
import java.util.Calendar;

import org.apache.axis.types.NonNegativeInteger;

import com.fedex.rate.stub.Address;
import com.fedex.rate.stub.ClientDetail;
import com.fedex.rate.stub.Dimensions;
import com.fedex.rate.stub.DropoffType;
import com.fedex.rate.stub.LinearUnits;
import com.fedex.rate.stub.Money;
import com.fedex.rate.stub.PackageRateDetail;
import com.fedex.rate.stub.PackagingType;
import com.fedex.rate.stub.Party;
import com.fedex.rate.stub.RatePortType;
import com.fedex.rate.stub.RateReply;
import com.fedex.rate.stub.RateReplyDetail;
import com.fedex.rate.stub.RateRequest;
import com.fedex.rate.stub.RateRequestType;
import com.fedex.rate.stub.RateServiceLocator;
import com.fedex.rate.stub.RatedPackageDetail;
import com.fedex.rate.stub.RatedShipmentDetail;
import com.fedex.rate.stub.RequestedPackageLineItem;
import com.fedex.rate.stub.RequestedShipment;
import com.fedex.rate.stub.ServiceType;
import com.fedex.rate.stub.ShipmentRateDetail;
import com.fedex.rate.stub.Surcharge;
import com.fedex.rate.stub.VersionId;
import com.fedex.rate.stub.WebAuthenticationCredential;
import com.fedex.rate.stub.WebAuthenticationDetail;
import com.fedex.rate.stub.Weight;
import com.fedex.rate.stub.WeightUnits;


public class Client {
	

	public static void main(String[] args) {  
		ClientDetail clientDetail = new ClientDetail();
        clientDetail.setAccountNumber("510087801");
        clientDetail.setMeterNumber("118511978");
        
        WebAuthenticationCredential wac = new WebAuthenticationCredential();
        wac.setKey("W7rooeZpAjWwNqos");
        wac.setPassword("XfCy1kWCicw2uGab4wqrsgdmU");
        
        VersionId versionId = new VersionId("crs", 10, 0, 0);

		RateRequest request = new RateRequest();
	    request.setClientDetail(clientDetail);
        request.setWebAuthenticationDetail(new WebAuthenticationDetail(wac));
        request.setVersion(versionId);
        
	    Address shipperAddress = new Address(); 
	    shipperAddress.setStreetLines(new String[] {"6233 Winchester Rd"});
	    shipperAddress.setCity("Memphis");
	    shipperAddress.setStateOrProvinceCode("TN");
	    shipperAddress.setPostalCode("38115");
	    shipperAddress.setCountryCode("US");
	    
        Party shipper = new Party();
        shipper.setAddress(shipperAddress);

	    Address recipientAddress = new Address(); 
	    recipientAddress.setStreetLines(new String[] {"8001 Pauline Vanier"});
	    recipientAddress.setCity("Anjou");
	    recipientAddress.setStateOrProvinceCode("PQ");
	    recipientAddress.setPostalCode("H1J2V8");
	    recipientAddress.setCountryCode("CA");
	    
        Party recipient = new Party();
	    recipient.setAddress(recipientAddress);
	    
        RequestedPackageLineItem rp = new RequestedPackageLineItem();
	    rp.setWeight(new Weight(WeightUnits.KG, new BigDecimal(15.0)));
	    rp.setDimensions(new Dimensions(new NonNegativeInteger("10"), new NonNegativeInteger("100"), new NonNegativeInteger("10"), LinearUnits.CM));
	    
        RequestedShipment requestedShipment = new RequestedShipment();
        requestedShipment.setShipTimestamp(Calendar.getInstance());
        requestedShipment.setDropoffType(DropoffType.REGULAR_PICKUP);
        requestedShipment.setServiceType(ServiceType.INTERNATIONAL_PRIORITY);
        requestedShipment.setPackagingType(PackagingType.FEDEX_ENVELOPE);
	    requestedShipment.setRecipient(recipient);
        requestedShipment.setShipper(shipper);
        
	    request.setRequestedShipment(requestedShipment);
	    
	    requestedShipment.setRequestedPackageLineItems(new RequestedPackageLineItem[] {rp});

		try {
			RateServiceLocator service = new RateServiceLocator();
			RatePortType port = service.getRateServicePort();
			RateReply reply = port.getRates(request);
			
			RateReplyDetail[] rrds = reply.getRateReplyDetails();
			for (int i = 0; i < rrds.length; i++) {
				RateReplyDetail rrd = rrds[i];
				System.out.println("service type " + rrd.getServiceType().toString());
			}
			
			
		} catch (Exception e) {
		    e.printStackTrace();
		} 
	}
	
}
